home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 061-070 / amok62 / sorting / sorting.def < prev    next >
Encoding:
Modula Definition  |  1993-11-04  |  2.4 KB  |  66 lines

  1. (******************************************************************************
  2.  
  3.     :Program.    Sorting.def
  4.     :Contents.   procedure for sorting
  5.     :Author.     Markus Uhlendahl
  6.     :Address.    Vorm Burgtor 16, D-4408 Dülmen
  7.     :Phone.      02594/81540
  8.     :Language.   Modula-2
  9.     :Translator. M2Amiga 4.0d
  10.     :Copyright.  Public Domain
  11.     :History.    15.11.91 --- 1.0 --- first release
  12.  
  13. ******************************************************************************)
  14. DEFINITION MODULE Sorting;
  15.  
  16.  
  17. TYPE
  18.   SwapProcedure=PROCEDURE (LONGINT,LONGINT);
  19. (*
  20.  * FUNCTION     swap two elements of an array
  21.  *              Swaps two elements of an array.
  22.  * INPUTS       LONGINT = index of an element in the array
  23.  *              LONGINT = index of an element in the array
  24.  *
  25.  *)
  26.   Comparison=PROCEDURE (LONGINT,LONGINT) : BOOLEAN;
  27. (*
  28.  * FUNCTION     compare two elements
  29.  *              Compares two elements of an array.
  30.  * INPUTS       LONGINT = index of an element in the array
  31.  *              LONGINT = index of an element in the array
  32.  * RESULTS      TRUE if the comparison is TRUE else FALSE
  33.  *
  34.  *)
  35.  
  36.  
  37. PROCEDURE QuickSort (first,last : LONGINT;
  38.                      Lower      : Comparison;
  39.                      Swap       : SwapProcedure;
  40.                      ascending  : BOOLEAN);
  41. (*
  42.  * FUNCTION     sort an array
  43.  *              This implementation of the quicksort-algorythm is very
  44.  *              flexible. It sorts arrays of every type and the user can
  45.  *              choose if the array is sorted ascending or not. To make this
  46.  *              possible the user has to write two procedures. One that
  47.  *              compares two elements of the array and one that swaps two
  48.  *              elements.
  49.  * INPUTS       first = first index of the array
  50.  *              last = last index of the array
  51.  *              Lower = PROCEDURE which compares two elements of the array
  52.  *                      returns TRUE if the first element of the comparison
  53.  *                      is really lower (a<b) than the second element
  54.  *              Swap = PROCEDURE which swaps two elements of the array
  55.  *              ascending = if ascending is TRUE the first element of the
  56.  *                          array will be the smallest and the last element
  57.  *                          the greatest
  58.  *                          if ascending is FALSE it will be vice versa
  59.  * BUGS         none known
  60.  * AUTHOR       Markus Uhlendahl
  61.  *
  62.  *)
  63.  
  64.  
  65. END Sorting.
  66.